﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices.Admin;
using Shop.Model.Dto.Admin.Jur;
using Shop.Model.View.Admin.Jur;
using Shop.Model.View.Admin.JurUser;

namespace Shop.AdminApi.Controllers;

/// <summary>
/// 登录服务
/// </summary>
[ApiController]
[Route("admin/[controller]")]
public class AcountController: ShopControllerBase
{
    private readonly IAccountService _appService;
    private readonly IUserContext _userContext;
    
    /// <summary>
    /// 
    /// </summary>
    /// <param name="appService"></param>
    public AcountController(IAccountService appService,IUserContext userContext)
    {
        _appService = appService;
        _userContext = userContext;
    }
    
    /// <summary>
    /// 管理员登录
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("Login")]
    [AllowAnonymous]
    public async Task<AppResult<AdminLoginVo>> AdminLogin(AdminLoginDto dto)
    {
        try
        {
            var date = await _appService.AdminLogin(dto);
            return date;
        }
        catch (Exception ex)
        {
            return Problem(ex.ToString());
        }
    }

    /// <summary>
    /// 获取管理员信息
    /// </summary>
    /// <returns></returns>
    [HttpGet("AdminInfo")]
    public AppResult<AdminInfoVo> AdminInfo()
        => _appService.AdminInfo(_userContext.Id);
}
